const path = require("path")
const CleanWebpackPlugin = require("clean-webpack-plugin")
const CopyWebpackPlugin = require("copy-webpack-plugin")
const Visualizer = require("webpack-visualizer-plugin")
const merge = require("webpack-merge")
const base = require("./index")

module.exports = function(env) {
  console.log(env)
  let { mode } = env
  let prodConfig = {
    mode: "production",
    devtool: mode === "production" ? false : "source-map",
    plugins: [
      new CleanWebpackPlugin(["dist/app"], {
        root: path.join(__dirname, "../../"),
        verbose: true,
        dry: false
      }),
      new CopyWebpackPlugin([{ from: "./app/resource/", to: "../" }]),
      new Visualizer()
    ]
  }
  prodConfig = merge(base(env), prodConfig)
  return prodConfig
}
